﻿/// <reference path="../Ext4.0/ext-all.js" />


var RoleTypeStore = Ext.create('Ext.data.Store', {
    remoteSort: true,
    fields: ['value', 'name'],
    proxy: {
        type: 'ajax',
        url: "OrgnizationMag.aspx?action=BindRoleType",
        actionMethods: 'post',
        reader: {
            type: 'json',
            root: 'data'
        }
    }
})

RoleTypeStore.load();

var AddInfoForm = Ext.create('Ext.form.Panel', {
    id: "frmAdd",
    width: 300,
    height: 310,
    plain: true,
    frame: true,
    labelWidth: 45,
    defaultType: "textfield",
    baseCls: "x-plain",
    layout: 'anchor',
    defaults: { anchor: "95%", msgTarget: "side" },
    url: "OrgnizationMag.aspx?action=Add",
    // The fields
    defaultType: 'textfield',
    items: [{
        fieldLabel: '级别名称',
        name: 'OrgName',
        allowBlank: false,
        blankText: "级别名称"
    }, {
        fieldLabel: '上级',
        name: 'ParentID',
        hidden: true
    }, {
        name: "ParentName",
        fieldLabel: "上级名称",
        allowBlank: true,
        value: ParentName,
        listeners: {
            'focus': function () {
                ParentOrg();
            }
        }

    }, {
        fieldLabel: '描述',
        name: 'Describe',
        allowBlank: true
    }, {
        name: "RoleType",
        xtype: 'combobox',
        fieldLabel: '级别类型',
        store: RoleTypeStore,
        valueField: 'value',
        allowBlank: false,
        displayField: 'name',
        triggerAction: "all"
    }],

    buttonAlign: "center",
    bodyStyle: "padding:0 0 0 0",
    buttons: [{
        text: '新增',
        formBind: true,
        disabled: true,
        handler: function () {

            var form = Ext.getCmp('frmAdd').getForm();
            if (form.isValid()) {
                form.submit({
                    success: function (form, action) {
                        Ext.Msg.alert("恭喜", "新增成功");
                        StorePage.load();
                        ParentID = "";
                        ParentName = "";
                        addWin.hide();
                    },
                    failure: function (form, action) {
                        Ext.Msg.alert('Failed', action.result.msg);
                    }
                });
            }
        }
    }]
});
var addWin = Ext.create('Ext.window.Window', {
    title: '新增机构',
    width: 320,
    height: 250,
    layout: 'fit',
    labelWidth: 100,
    closeAction: 'hide',
    resizable: false,
    modal: 'true',
    iconCls: "addicon",
    items: AddInfoForm,
    listeners: {
            "show": function () {
                AddInfoForm.getForm().reset();
            }
    }
});

